package com.hjqjl.common_lib.base;

import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.fragment.app.Fragment;
import androidx.viewbinding.ViewBinding;

import com.hjqjl.common_lib.utils.ViewBindingCreator;

public abstract class ComLibFragment<VB extends ViewBinding> extends Fragment {
    public VB pVBinding;

    @Nullable
    @Override
    public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        //对ViewBinding的封装
        pVBinding = ViewBindingCreator.createViewBinding(getClass(), getLayoutInflater());
        View rootView = generateContentView(pVBinding == null ? getContentView() : pVBinding.getRoot());
        return rootView;
    }

    @Override
    public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) {
        super.onViewCreated(view, savedInstanceState);
        initData();
        initListener();
    }

    /**
     * 初始化数据
     */
    public void initData() {
    }

    /**
     * 初始化点击事件
     */
    public void initListener() {
    }

    protected View getContentView() {
        return null;
    }

    //便于子类重载后扩充contentView,(这个意思，我这里没实现：例如BaseToolbarActivity就是实现了这个方法，对contentView进一步包装后再返回。)
    protected View generateContentView(View contentView) {
        return contentView;
    }
}
